<link rel="stylesheet" href="<?php echo $this->webroot;?>css/bootstrap-tagsinput.css"/>
<script type="text/javascript" src="<?php echo $this->webroot;?>js/typeahead.min.js"></script>    
<script type="text/javascript" src="<?php echo $this->webroot;?>js/bootstrap-tagsinput.min.js"></script>    
<div class="row">
    <div class="col-md-8 col-md-offset-2" style="background: #fff; padding-bottom: 50px;">
        <form role="form" name="Bookmaker" method="post" action="<?php echo $this->webroot?>Bookmakers/save" >
          <input type="hidden" name="BookmakerLang[ita][id]" value="" />
          <input type="hidden" name="BookmakerLang[eng][id]" value="" />
          <input type="hidden" name="Bookmaker[id]" id="bookmaker_id" value="" />
          <br>
		  <div class="row">
	          <div class="form-group col-md-12">
	            <label for="nome">Nome:</label>
	            <input type="text" class="form-control" id="nome" name="Bookmaker[nome]" value="" placeholder="Inserisci il nome" />
	          </div>
          </div>
		  <div class="row">
	          <div class="col-md-12">
	           <!-- Nav tabs -->
	            <ul class="nav nav-tabs">
	              <li class="active"><a href="#ita" data-toggle="tab">Ita</a></li>
	              <li><a href="#eng" data-toggle="tab">Eng</a></li>
	            </ul>
	            <!-- Tab panes -->
	            <div class="tab-content">
	              <div class="tab-pane fade in active" id="ita">
	                 <div class="form-group">
	                    <label for="descrizione">Descrizione italiano:</label>
	                    <textarea rows="10" class="form-control" name="BookmakerLang[ita][descrizione]" ></textarea>
	                  </div>
	              </div>
	              <div class="tab-pane fade in" id="eng">
	                   <div class="form-group">
	                    <label for="descrizione">Descrizione inglese:</label>
	                    <textarea rows="10" class="form-control" name="BookmakerLang[eng][descrizione]" ></textarea>
	                  </div>
	              </div>
	            </div>
          	  </div>
          </div>
          
         
		  <div class="row">
	          <div class="form-group  col-md-12">
	            <label for="link">Link:</label>
	            <input type="text" class="form-control" id="link" name="Bookmaker[link]" value="" placeholder="Inserisci il link" />
	          </div>   
          </div>
		  <div class="row">
	          <div class="form-group col-md-12">
	            <label for="email">Email:</label>
	            <input type="text" class="form-control" id="email" value=""  name="Bookmaker[email]" placeholder="Inserisci l'email" />
	          </div>  
          </div>
		  <div class="row">
	          <div class="form-group col-md-6">
	            <label for="bonus"><?php echo __("Telefono"); ?>:</label>
	            <input type="text" class="form-control" id="puntmin" value="" name="Bookmaker[telefono]" placeholder="Inserisci recapito telefonico" />
	          </div>   
	          <div class="form-group col-md-6">
	            <label for="maxbonus"><?php echo __("Fax"); ?>:</label>
	            <input type="text" class="form-control" id="versmin" value="" name="Bookmaker[fax]" placeholder="Inserisci fax" min="0" />
	          </div>   
          </div>
		  <div class="row">
	          <div class="form-group col-md-4">
	            <label for="puntmin">Puntata Minima:</label>
	            <input type="text" class="form-control" id="puntmin" value="" name="Bookmaker[puntata_minima]" placeholder="Inserisci la puntata minima" />
	          </div>   
	          <div class="form-group col-md-4">
	            <label for="versmin">Versamento Minimo:</label>
	            <input type="text" class="form-control" id="versmin" value="" name="Bookmaker[versamento_minimo]" placeholder="Inserisci il versamento minimo" min="0" />
	          </div>   
	          <div class="form-group col-md-4">
	            <label for="verprelminsmin">Prelievo Minimo:</label>
	            <input type="text" class="form-control" id="prelmin" value="" name="Bookmaker[prelievo_minimo]" placeholder="Inserisci il prelievo minimo  " min="0" />
	          </div>   
          </div>
		  <div class="row">
	          <div class="form-group col-md-12">
	            <label for="categorie">Categorie:</label>
	            <select name="Bookmaker[categoria][]" style="" id="categorie" multiple="multiple">
	                <?php foreach($categorie as $key=>$temp){?>
	                    <option value="<?php echo $key?>" ><?php echo $temp ?></option>
	                <?php }?>
	            </select> 
	          </div> 
          </div>
		  <div class="row">
	          <div class="form-group col-md-12">
	            <label for="valuta">Valuta:</label>
	            <select name="Bookmaker[valuta][]" style="" class="" id="valuta" multiple="multiple">
	                <?php foreach($valute as $key=>$temp){?>
	                    <option  value="<?php echo $key?>" ><?php echo $temp["code"] ?></option>
	                <?php }?>
	            </select> 
	            <!-- value="<?php echo $bookmaker["Bookmaker"]["valuta"];?>"  name="Bookmaker[valuta]" placeholder="Associa la valuta"> -->
	          </div>
          </div>
		  <div class="row">
	          <div class="col-md-12 pull-right" >
	              <button type="submit" class="btn btn-primary">Salva</button>
	              <a  href="<?php echo $this->webroot?>Bookmakers/index" class="btn">Annulla</a>
	          </div>
          </div>
        </form>
   </div>
  </div>



  <script>
	
	$(".fileinput").on("change", function(){
        var files = this.files;
        var data = null;
        var path = $(this).data("action");
        var attachTipo = $(this).data("attach-tipo");
        var objectId = $(this).data("object-id");
        for(var i = 0; i < files.length; i++) {
            data = new FormData();
            var xhr = new XMLHttpRequest();
            xhr.onreadystatechange = function(ev){
            	console.log(ev);
            };
             xhr.onload = function(){
               data = jQuery.parseJSON(this.responseText);
               //console.log(data);
               if (data.success==true) {
                    oImg = $("#logo");
                    // console.log(oImg);
                    oImg.data("id",data.filesuploaded[0].id);
                    oImg.attr("src","<?php echo $this->webroot; ?>" + data.filesuploaded[0].thumb_webpath);
               } else if (data.success==false) {
                    setFlash(data.message,data.level);
               }
            };
            xhr.open('POST', path, true);
            data.append(attachTipo, files[i]);
    	    data.append('attachTipo', attachTipo);
    	    data.append('objectId', objectId);
            xhr.send(data);
        }
	});
    
    function format(data) {
        console.log(data);
        return "<img class='banner_thumb' src='<?php echo $this->webroot?>" + data.id + "'/>" + data.text;
    }
    
    $(document).ready(
        function() { 
            $('#valuta').select2({
                placeholder:"Seleziona una Valuta"
            }); 
            $('#categorie').select2({
                placeholder:"Seleziona una Categoria"
            }); 
        });
      
  </script>